{% extends 'user/udai_welcome.html' %}
{% load static %}


<div class="content clearfix bgf5">
    <section class="user-center inner clearfix">

        {% block siyou %}
            <div class="pull-right">
                <div class="user-content__box clearfix bgf">
                    <div class="title">订单中心-我的订单</div>
                    <div class="order-list__box bgf">
                        <div class="order-panel">
                            <ul class="nav user-nav__title" role="tablist">
                                <li role="presentation" class="nav-item active"><a href="" aria-controls="all" role="tab" data-toggle="tab">所有订单</a>
                                </li>
                                <li role="presentation" class="nav-item "><a href="" aria-controls="pay" role="tab" data-toggle="tab">待付款 <span class="cr">{{a1.count}}</span></a></li>
                                <li role="presentation" class="nav-item "><a href="" aria-controls="emit" role="tab" data-toggle="tab">待发货 <span class="cr">{{a4.count}}</span></a></li>
                                <li role="presentation" class="nav-item "><a href="" aria-controls="take" role="tab" data-toggle="tab">待收货 <span class="cr">{{a2.count}}</span></a></li>
                                <li role="presentation" class="nav-item "><a href="" aria-controls="eval" role="tab" data-toggle="tab">待评价 <span class="cr">{{a3.count}}</span></a></li>
                            </ul>


							<div class="tab-content">
								<div role="tabpanel" class="tab-pane fade in active" id="all">
									<table class="table text-center">
										<tr>
											<th width="380">商品信息</th>
											<th width="85">单价</th>
											<th width="85">数量</th>
											<th width="120">实付款</th>
											<th width="120">交易状态</th>
											<th width="120">交易操作</th>
										</tr>
                                        {% csrf_token %}
                                        {% for foo in page %}
										<form action="{%url 'order:pay'%}" method="post" class="foo1">
										{% csrf_token %}

											<input type="hidden" name="order_id" value="{{foo.id}}" >


										<tr class="order-item">
											<td>
												<label>
													<a href="../../../templates/udai_order_detail.html" class="num">
														{{ foo.create_time }} 订单号: {{ foo.code }}
													</a>
													<div class="card">
														<div class="img"><img src="{{ foo.goods.image }}" alt="" class="cover"></div>
														<div class="name ep2">{{ foo.goods.name }}</div>
														<div class="format">颜色分类：{{ foo.goods.color.color }}  尺码：{{ foo.goods.size.size }}</div>
													</div>
												</label>
											</td>
											<td class="danjia">{{ foo.goods.price }}</td>
											<td class="num1">{{ foo.num }}</td>
											<td class="prices">￥{{foo.goods.price}}</td>
											<td class="state">


												<a class="but c6" id="status" >{{foo.status}}</a>
												<!--<a href="" class="but c9">订单详情</a>-->
											</td>
											<td class="order">
												<div class="del"><span class="glyphicon glyphicon-trash" aria-hidden="true" name="{{ foo.id }}"></span></div>
												<!--<a href="" class="but but-primary">立即付款</a>-->
												<input type="submit" value="立即付款" class="btn ma1" style="display: none">
												<a href="{%url 'order:confirm_receipt' foo.id %}"><input type="button" value="确认收货" class="btn ma2" style="display: none"></a>
												<a href=""><input type="button" value="立即评价" class="btn ma3" style="display: none"></a>
												<!-- <a href="" class="but but-link">评价</a> -->
											</td>
										</tr>
											</form>
                                        {% endfor %}

									</table>
									<div class="page text-right clearfix" style="margin-top: 40px">
										<nav aria-label="Page navigation">
                                            <div class="pagination" style="">
                                                <ul class="pagination">
                                                {% if page.has_previous %}
                                                    <li class="fenye"><a href="{% url 'order:udai_order' page.previous_page_number %}" aria-label="Previous" class="last">
                                                        <span aria-hidden="true">&laquo;</span></a>
                                                {% endif %}

                                                {% for num in page.paginator.page_range%}
                                                    {%if pindex == page.number%}
                                                        <a href="">{{ num }}</a>
                                                    {%else%}
                                                        <a href="{% url 'order:udai_order' num %}" class="now">{{ num }}</a>
                                                    {%endif%}
                                                 {% endfor %}

                                                 {% if page.has_next %}
                                                     <a href="{% url 'order:udai_order' page.next_page_number %}" aria-label="Next" class="next">
                                                          <span aria-hidden="true">&raquo;</span></a></li>
                                                  {% endif %}
                                                </ul>
                                            </div>
                                        </nav>
									</div>
								</div>

							</div>
						</div>
					</div>

				</div>
			</div>
                <script>
	$('.order-item').each(function () {
			var a = $(this).find('.c6');
			var b = $(this).find('.ma1');
			var c = $(this).find('.ma2');
			var d = $(this).find('.ma3');
			console.log(b,'99999999');
			console.log(a[0].text);
			if (a[0].text === "0"){
			    a.html('未付款');
				b.css('display','block');
				c.css('display','none');
				d.css('display','none');

			}else if (a[0].text === '1'){
			    a.html('待发货')

			}else if (a[0].text === '2'){
			    a.html('待收货');
				c.css('display','block');
				b.css('display','none');
				d.css('display','none');
			}else if (a[0].text === '3'){
			    a.html('已完成');
			    d.css('display','block');
			    b.css('display','none');
				c.css('display','none');

			}
    });
    $(function() {

        $('.glyphicon').click(function () {
            var a=confirm("确认删除么?");
            var b=$('input[name="csrfmiddlewaretoken"]').attr('value');
            var c= $(this).attr('name');
            var d = $(this).parent().parent().parent();
            console.log(b);
            if(a === true) {
                $.ajax({
                    url: "http://127.0.0.1:8000/order/del_order/",
                    type: "post",
                    dataType:'json',
                    headers: {"X-CSRFToken":b},
                    data: {
                        'order_id':c,
                    },
                    success:function (res){
                        var obj = JSON.stringify(res);
                        console.log(obj);
                        if(obj === '{"mse":"删除成功"}'){
                            d.remove()
                        }else{
                            alert(obj);
                        }

                    },
                    error:function(resp){        
                        alert("状态码"+resp.status)
                                                }

                })
            }
        })
    })

</script>
			{% endblock %}
		</section>
	</div>
